<?php
define();
class CI_Controller 
{
	public function __construct()
	{
		define('ENVIRONMENT', 'development');
		if (defined('ENVIRONMENT'))
		{
			switch (ENVIRONMENT)
			{
				case 'development':
					error_reporting(E_ALL);
				break;
			
				case 'testing':
				case 'production':
					error_reporting(0);
				break;
			}
		}
		//cli 
		if (defined('STDIN'))
		{
			chdir(dirname(__FILE__));
		}
		define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
		define('EXT', '.php');
		@set_magic_quotes_runtime(0); // Kill magic quotes
		
		
		if (function_exists("set_time_limit") == TRUE AND @ini_get("safe_mode") == 0)
		{
			@set_time_limit(300);
		}
		$EXT =& load_class('Hooks', 'core');
		$EXT->_call_hook('pre_system');
		$CFG =& load_class('Config', 'core');
		$UNI =& load_class('Utf8', 'core');
		$OUT =& load_class('Output', 'core');
		if ($EXT->_call_hook('cache_override') === FALSE)
		{
			if ($OUT->_display_cache($CFG, $URI) == TRUE)
			{
				exit;
			}
		}
		$SEC =& load_class('Security', 'core');
		$IN	=& load_class('Input', 'core');
		$EXT->_call_hook('pre_controller');
		$EXT->_call_hook('post_controller_constructor');
		$EXT->_call_hook('post_controller');
		if ($EXT->_call_hook('display_override') === FALSE)
		{
			$OUT->_display();
		}
		$EXT->_call_hook('post_system');
		if (class_exists('CI_DB') AND isset($CI->db))
		{
			$CI->db->close();
		}
	}
}